import { observable, action, toJS } from 'mobx';
import { WeaForm } from 'comsMobx';

import * as API from '../apis/seatCard';

export default class SeatCardStore {
  @observable seatCardVisible = false;
  @observable printPreviewVisible = false;
  @observable printSetVisible = false;
  @observable form = new WeaForm();
  @observable conditions = [];
  @observable shareFields = [];
  @observable setForm = new WeaForm();
  @observable setConditions = [];
  @observable mouldcontent = '';
  @observable hrmInfo = [];
  @action 
  setState = (params) => {
    Object.keys(params).forEach(key => {
      this[key] = params[key];
    });
  }

  getPrintCardSet = (params) => {
    API.getPrintCardSet(params).then(res => {
      if (res && res.api_status) {
        let fields = toJS(res.fields);
        this.form.initFormFields(fields);
        this.conditions = fields;
      }
    });
  }

  getPrintUp = () => {
    API.getPrintUp().then(res => {
      if (res && res.api_status) {
        let fields = toJS(res.condition);
        this.setForm.initFormFields(fields);
        this.setConditions = fields;
      }
    });
  }

  getBeforePrintInfo = (params, callback) => {
    API.getBeforePrintInfo(params).then(res => {
      if (res && res.api_status) {
        this.hrmInfo = res.info;
        typeof callback === 'function' && callback();
      }
    })
  }

  // 获取席卡模板
  getCardMouldSet = (params, callback) => {
    API.getCardMouldSet(params).then(res => {
      if (res && res.api_status) {
        this.mouldcontent = res.mouldcontent;
        typeof callback === 'function' && callback();
      }
    })
  }

}